export const r4_adc_resolution_setting = function () {
    var resolution = this.getFieldValue('RESOLUTION');
    var code = 'analogReadResolution(' + resolution + ');';
    return code;
}

export const r4_onboard_dot_matrix_display = function (_, generator) {
    generator.definitions_['include_Arduino_LED_Matrix'] = '#include "Arduino_LED_Matrix.h"\n';
    generator.definitions_['var_declare_Arduino_LED_Matrix'] = 'ArduinoLEDMatrix matrix;';
    generator.setups_['var_declare_Arduino_LED_Matrix'] = 'matrix.begin();';
    var data = generator.valueToCode(this, 'DATA', generator.ORDER_ATOMIC);
    var code = 'matrix.renderBitmap(' + data + ', 8, 12);';
    return code;
}

export const r4_display_matrix_led_array = function (_, generator) {
    var varName = this.getFieldValue('VAR');
    var a = this.getFieldValue('BITMAP');
    var code = '{\n';
    for (var i = 0; i <= 7; i++) {
        var tmp = '';
        for (var j = 0; j <= 11; j++) {
            tmp = tmp + a[i][j] + ',';
        }
        tmp = tmp + ',';
        tmp = tmp.replace(/,,/g, '');
        tmp = '  {' + tmp + '},\n';
        code = code + tmp;
    }
    code = code + ',';
    code = code.replace(/,,/g, '');
    code += '};';
    code = code.replace(/,}/g, '}');
    generator.definitions_[varName] = 'byte ' + varName + '[8][12] = ' + code;
    return [varName, generator.ORDER_ATOMIC];
}